<table class="va-top">
<?php
$edit_btn = BUtils::T('edit_btn');
$delete_btn = BUtils::T('delete_btn');
$submit_btn = BUtils::T('submit_btn');
$submitted_lbl = BUtils::T('submitted_lbl');
$published_lbl = BUtils::T('published_lbl');
$preview_btn = BUtils::T('preview_btn');

foreach ($model as $k => $row) {
	$url_picture = BUtils::GetPictureUrl($row['url_picture']);
	
	$publish_time = null;
	if ($row['status'] == 2 and $row['uts_published'] > 0) {
		$publish_time = BUtils::T('published_time_lbl') . ': ' . date('Y-m-d H:i:s', $row['uts_published']);
	}
	
	//name
	$name = (empty($row['number']) ? '' : $row['number'] . '. ') . $row['name'];
	
	//price
	$price = Yii::app()->locale->numberFormatter->formatCurrency($row['price'], 'EUR');
	
	//half description
	$description = BUtils::SubString($row['description'], 100);
?>
<tr>
	<td class="picture-field">
		<a class="pic preview-btn" href="<?php echo Yii::app()->createUrl('/menu/preview', array('id'=>$row['id'])); ?>">
			<img id="dish_picture" style="width:100px;" src="<?php echo $url_picture; ?>" alg="" />
		</a>
<?php
/*
$timeText = '';
if ($row['status'] == 1) $timeText = date('Y-m-d H:i', $row['uts_submitted']);
else if ($row['status'] == 2) $timeText = date('Y-m-d H:i', $row['uts_published']);
echo '<div class="eg">' . $timeText . '</div>';
*/
?>
	</td>
	<td class="title-field">
		<div class="title"><?php echo $name; ?></div>
		<div class="address"><?php echo $description; ?></div>
		<div class="buttons">
<?php
// preview button
echo CHtml::link("<span>{$preview_btn}</span>", Yii::app()->createUrl('/menu/preview', array('id'=>$row['id'])), array('class'=>'button button-small button-thin preview-btn'));
echo ' ';
echo CHtml::link("<span>{$edit_btn}</span>", Yii::app()->createUrl('/menu/form', array('id'=>$row['id'])), array('class'=>'button button-small button-thin'));
echo ' ';
echo CHtml::link("<span>{$delete_btn}</span>", Yii::app()->createUrl('/menu/delete', array('id'=>$row['id'])), array('class'=>'button button-small button-thin delete-btn'));
echo ' ';
/* no submit function here:
if ($row['status'] == 1) {
	echo CHtml::link("<span>{$submitted_lbl}</span>", 'javascript:;', array('class'=>'button button-small button-thin button-disabled', 'rel'=>'tipsy', 'title'=>BUtils::T('submit_btn_eg')));
} else if ($row['status'] == 2) {
	echo CHtml::link("<span>{$published_lbl}</span>", 'javascript:;', array('class'=>'button button-small button-thin button-disabled', 'rel'=>'tipsy', 'title'=>$publish_time));
} else {
	echo CHtml::link("<span>{$submit_btn}</span>", Yii::app()->createUrl('/menu/submit', array('id'=>$row['id'])), array('class'=>'button button-small button-thin button-compliment submit-btn unpub'));
}*/
?>
		</div>
	</td>
	<td class="period-field">
		<span style="background-color:#F1F1F1; border:1px solid #DDDDDD; border-radius:12px; color:#555; font-weight:bold; padding:3px 14px;">
			<?php echo $price; ?>
		</span>
	</td>
</tr>
<?php
}
?>
</table>
<script type="text/javascript">
$(function() {
	$('.delete-btn').click(function() {
		if (confirm('<?php echo BUtils::T('delete_btn_confirm'); ?>')) {
			var _this = $(this);
			if (_this.attr('disabled')) {
				return false;
			}
			jQuery.ajax({
				'url':_this.attr('href'),
				'beforeSend':function() {
					_this.attr('disabled','disabled').addClass('button-disabled');
				},
				'success':function(html) {
					_this.removeAttr('disabled').removeClass('button-disabled');
					_this.parent().parent().parent().fadeOut('slow');
				}
			});
		}
		return false;
	});
	$('.submit-btn').click(function() {
		if (confirm('<?php echo BUtils::T('submit_btn_confirm'); ?>')) {
			var _this = $(this);
			if (_this.attr('disabled')) {
				return false;
			}
			jQuery.ajax({
				'url':_this.attr('href'),
				'beforeSend':function() {
					_this.attr('disabled','disabled').addClass('button-disabled');
				},
				'success':function(html) {
					_this.removeAttr('disabled').removeClass('button-disabled');
					_this.parent().children('.unpub').hide();
				}
			});
		}
		return false;
	});
	$('.preview-btn').click(function() {
		var _this = $(this);
		if (_this.attr('disabled')) {
			return false;
		}
		jQuery.ajax({
			'url':_this.attr('href'),
			'beforeSend':function(){
				$('#menuItem-preview').html('<img src="<?php echo Yii::app()->baseUrl; ?>/images/loader-bar.gif" />');
			},
			'success':function(html){
				$('#menuItem-preview').html(html);
				$('.popupPicture').fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'overlayShow'	:	true
				});
			}
		});
		return false;
	});
});
</script>